﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <el-form ref="formRefEquipment" :model="stateEquipment.vmModel" label-width="100px">
    <div style="margin-bottom:10px;">{{$t('message.autotrans.SysBatchEditConfirm')}}</div>
    <el-row>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_EquipName_FormItem" prop="LinkedVM.EquipName" :label="$t('message.autotrans._Model_Equipment_EquipName')">
          <el-input v-model="stateEquipment.vmModel.LinkedVM.EquipName" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_EquipCode_FormItem" prop="LinkedVM.EquipCode" :label="$t('message.autotrans._Model_Equipment_EquipCode')">
          <el-input v-model="stateEquipment.vmModel.LinkedVM.EquipCode" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_EquipType_FormItem" prop="LinkedVM.EquipType" :label="$t('message.autotrans._Model_Equipment_EquipType')">
          <el-select v-model="stateEquipment.vmModel.LinkedVM.EquipType" clearable>
             <el-option key="Equipment" value="Equipment" :label="$t('message.autotrans._Enum_EquipTypeEnum_Equipment')"></el-option>
             <el-option key="Tooling" value="Tooling" :label="$t('message.autotrans._Enum_EquipTypeEnum_Tooling')"></el-option>
             <el-option key="Mould" value="Mould" :label="$t('message.autotrans._Enum_EquipTypeEnum_Mould')"></el-option>
          </el-select>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_SpotType_FormItem" prop="LinkedVM.SpotType" :label="$t('message.autotrans._Model_Equipment_SpotType')"          :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_Equipment_SpotType')}), trigger: 'blur' }]" >
          <el-select v-model="stateEquipment.vmModel.LinkedVM.SpotType" clearable>
             <el-option key="Barcode" value="Barcode" :label="$t('message.autotrans._Enum_EquipSpotCheckEnum_Barcode')"></el-option>
             <el-option key="Itemized" value="Itemized" :label="$t('message.autotrans._Enum_EquipSpotCheckEnum_Itemized')"></el-option>
             <el-option key="None" value="None" :label="$t('message.autotrans._Enum_EquipSpotCheckEnum_None')"></el-option>
          </el-select>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_DriverType_FormItem" prop="LinkedVM.DriverType" :label="$t('message.autotrans._Model_Equipment_DriverType')"          :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_Equipment_DriverType')}), trigger: 'blur' }]" >
          <el-select v-model="stateEquipment.vmModel.LinkedVM.DriverType" clearable>
             <el-option key="OpcUa" value="OpcUa" :label="$t('message.autotrans._Enum_DriverTypeEnum_OpcUa')"></el-option>
             <el-option key="None" value="None" :label="$t('message.autotrans._Enum_DriverTypeEnum_None')"></el-option>
          </el-select>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_IpAddress_FormItem" prop="LinkedVM.IpAddress" :label="$t('message.autotrans._Model_Equipment_IpAddress')">
          <el-input v-model="stateEquipment.vmModel.LinkedVM.IpAddress" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_Port_FormItem" prop="LinkedVM.Port" :label="$t('message.autotrans._Model_Equipment_Port')">
          <el-input v-model="stateEquipment.vmModel.LinkedVM.Port" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_Actvie_FormItem" prop="LinkedVM.Actvie" :label="$t('message.autotrans._Model_Equipment_Actvie')">
          <el-select v-model="stateEquipment.vmModel.LinkedVM.Actvie" clearable>
             <el-option :key="1" :value=true :label="$t('message._system.common.vm.tips_bool_true')"></el-option>
             <el-option :key="0" :value=false :label="$t('message._system.common.vm.tips_bool_false')"></el-option>
          </el-select>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_Manufactor_FormItem" prop="LinkedVM.Manufactor" :label="$t('message.autotrans._Model_Equipment_Manufactor')">
          <el-input v-model="stateEquipment.vmModel.LinkedVM.Manufactor" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_Aux_1_FormItem" prop="LinkedVM.Aux_1" :label="$t('message.autotrans._Model_Equipment_Aux_1')">
          <el-input v-model="stateEquipment.vmModel.LinkedVM.Aux_1" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_Aux_2_FormItem" prop="LinkedVM.Aux_2" :label="$t('message.autotrans._Model_Equipment_Aux_2')">
          <el-input v-model="stateEquipment.vmModel.LinkedVM.Aux_2" clearable></el-input>
      </el-form-item>

      </el-col>
    </el-row>

    <div style="text-align:right;">
      <WtmButton @click="onSubmitEquipment"  type="primary" :button-text="$t('message.autotrans.SysSubmit')" style="margin-top:15px;"/>

      <WtmButton @click="onCloseEquipment"  type="primary" :button-text="$t('message.autotrans.SysClose')" style="margin-top:15px;"/>

    </div>

  </el-form>

</el-card>
</div>
</template>


<script setup lang="ts" name="message.autotrans._PageEquipmentManagementEquipmentBatchEdit;false">
import {  ElMessageBox, ElMessage,ElLoading } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { equipmentApi } from '/@/api/equipmentmanagement/equipment';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;


// 定义变量内容
const formRefEquipment = ref();
const stateEquipment = reactive({
    vmModel: {
	  LinkedVM:{
        EquipName: '',
        EquipCode: '',
        EquipType: undefined,
        SpotType: undefined,
        DriverType: undefined,
        IpAddress: '',
        Port: '',
        Actvie: undefined,
        Manufactor: '',
        Aux_1: '',
        Aux_2: '',
      },
      Ids:[],
      
	},
    
});

// 取消
const onCloseEquipment = () => {
    closeDialog();
};

// 提交
const onSubmitEquipment = () => {
	const loadingInstance = ElLoading.service({
		lock: true,
		text: '正在提交中，请等待。。。',
		background: 'rgba(0, 0, 0, 0.7)',
	});

    formRefEquipment.value?.validate((valid: boolean, fields: any) => {
		if (valid) {
            equipmentApi().batchedit(stateEquipment.vmModel).then(() => {
                ElMessage.success(ci.proxy.$t('message._system.common.vm.submittip'));
                emit('refresh');
                closeDialog();
            }).catch((error:any) => {
                other.setFormError(ci, error);
            }).finally(() => {
			loadingInstance.close();
		    })
		}
        else{
			loadingInstance.close();
        }
	})
};


// 页面加载时
onMounted(() => {
    
    if (ci.attrs["wtmdata"]) {
		stateEquipment.vmModel.Ids = ci.attrs["wtmdata"];
	}
	else if (useRouter().currentRoute.value.query.id) {
		stateEquipment.vmModel.Ids = useRouter().currentRoute.value.query.id as any;
	}

});

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh','closeDialog']);
// 关闭弹窗
const closeDialog = () => {
    emit('closeDialog');
};
// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

